package com.xingda.packing.dmss.minitor.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xingda.packing.dmss.common.R;
import com.xingda.packing.dmss.minitor.dto.AGVTaskDto;
import com.xingda.packing.dmss.minitor.dto.MesToAgv;
import com.xingda.packing.dmss.minitor.entity.PkAgvScheduling;
import com.xingda.packing.dmss.minitor.service.IPkAgvSchedulingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/agv")
@Slf4j
public class AGVController {
    @Resource
    private IPkAgvSchedulingService iPkAgvSchedulingService;

    @GetMapping("/getPage")
    public R getPage(Integer actionType,
                     Integer finishState,
                     Long current,
                     Long size) {
        try {
            IPage<PkAgvScheduling> pkEventsPage = this.iPkAgvSchedulingService.getList(actionType, finishState, current, size);
            return R.ok().put("data", pkEventsPage);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return R.error();
    }

    @GetMapping("/send")
    public R send(Integer id) {
        try {
            this.iPkAgvSchedulingService.send(id);
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return R.error();
    }

    @GetMapping("/status")
    public R status() {
        MesToAgv mesToAgv = iPkAgvSchedulingService.status();
        return R.ok().put("data", mesToAgv);
    }

    @PostMapping("/insert")
    public R insert(@RequestBody AGVTaskDto agvTaskDto) {
        log.info("执行了======================={}", agvTaskDto);
        iPkAgvSchedulingService.insert(agvTaskDto);
        return R.ok();
    }
}
